package cn.fl.project.controller;

import cmm.mid.core.framework.page.ListPageVO;
import cmm.mid.core.framework.page.Pager;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.DecimalUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.insroute.condition.InsRoutePrdInfoQC;
import cn.fl.insroute.service.IInsRoutePrdInfoService;
import cn.fl.insroute.vo.InsRoutePrdInfoVO;
import cn.fl.project.condition.PrjPrdBscInfoQueryCondition;
import cn.fl.project.service.IPrjPrdBscInfoService;
import cn.fl.project.vo.PrjPrdBscInfoVO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 车贷疫情项目审批流程
 */
@Controller
@RequestMapping("/project/cddywyq")
public class PrjYQController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(PrjYQController.class);

    @Autowired
    private IPrjPrdBscInfoService prjPrdBscInfoService;

    @Autowired
    private IInsRoutePrdInfoService insRoutePrdInfoService;

    /**
     * 项目产品初始化列表
     */
    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/prjPrdYQInitList.do", method = { RequestMethod.GET})
    @ResponseBody
    public Object initList(HttpServletRequest request) {
        String currentPage = request.getParameter("page");
        String pageSize = request.getParameter("pagesize");
        String prdNm = request.getParameter("prdNm");
        String prdMdl = request.getParameter("prdMdl");
        String prjId = request.getParameter("prjId");
        Pager page = new Pager();
        if (StringUtils.isNotEmpty(currentPage)) {
            page.setCurrentPage(Integer.parseInt(currentPage));
        }

        if (StringUtils.isNotEmpty(currentPage)) {
            page.setEveryPage(Integer.parseInt(pageSize));
        }

        PrjPrdBscInfoQueryCondition qc = new PrjPrdBscInfoQueryCondition();
        if (StringUtils.isNotEmpty(prdNm)) {
            qc.setPrdNm(prdNm);
        }
        if(StringUtils.isNotBlank(prdMdl)){
            qc.setPrdMdl(prdMdl);
        }
        if(StringUtils.isNotBlank(prjId)){
            qc.setPrjId(Long.valueOf(prjId));
        }
        page.setCondition(qc);
        Pager pager = this.prjPrdBscInfoService.searchListPage(page);
        List<PrjPrdBscInfoVO> prjPrdBscInfoVOS =  (List<PrjPrdBscInfoVO>)pager.getResultList();
        BaseLogUtils.info(logger, "initList", "初始化车辆列表数据prjPrdBscInfoVOS:" + JSON.toJSONString(prjPrdBscInfoVOS), CurrentThreadContext.getCurrentUserName());
        ListPageVO<PrjPrdBscInfoVO> listPage = new ListPageVO<PrjPrdBscInfoVO>(prjPrdBscInfoVOS, pager.getTotalCount());
        BaseLogUtils.info(logger, "initList", "查询数据完成. DATA:" + JSONObject.toJSONString(page), CurrentThreadContext.getCurrentUserName());
        return listPage;
    }

}
